﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.ChangeExecutionCounts, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_ChangeExecutionCounts : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.ChangeExecutionCounts;

        public override string name => LevelEditorConst.ChangeExecutionCounts;
        [Output("目标", false)] public EditorLevelServiceDynamicListSetter tagOrMcid;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.ChangeExecutionCounts, "修改类型")]
        public int type;
        public int value;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_ChangeExecutionCounts()
            {
                type = this.type,
                value = this.value,
                tagOrMcid = LevelServiceDynamicListSelectNode.DefaultParam
            };
            tagOrMcid = new EditorLevelServiceDynamicListSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }
        
        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_ChangeExecutionCounts rNode)
            {
                this.type = rNode.type;
                this.value = rNode.value;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_ChangeExecutionCounts rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}